<?php require VIEW_ROOT.'/common/header.php'?>

<style>
thead { cursor:pointer; }
tfoot { text-align:left; }
</style>

<script>
$(function(){
	$('thead').toggle(function(){
		$(this).parent().find('tbody').hide();
	},function(){
		$(this).parent().find('tbody').show();
	});
})
</script>

<div class="info">
			<?php echo date('Y年m月d日', $start_time); ?>
			~
			<?php echo date('Y年m月d日', $end_time); ?>
			&nbsp; / &nbsp;
			共 <b><?php echo ($end_time - $start_time) / 86400 + 1; ?></b> 天
			&nbsp; / &nbsp;
			共 <b><?php echo library_common::money_num($sum_all); ?></b> 元
			&nbsp; / &nbsp;
			<a href="./?m=finance&a=pay_analytics&start_time=<?php echo date('Y-m-d', $start_time - 86400 * 30); ?>&end_time=<?php echo date('Y-m-d', $end_time - 86400 * 30); ?>">上一个月</a>
			&nbsp; / &nbsp;
			<a href="./?m=finance&a=pay_analytics&start_time=<?php echo date('Y-m-d', $start_time + 86400 * 30); ?>&end_time=<?php echo date('Y-m-d', $end_time + 86400 * 30); ?>">下一个月</a>
</div>

<?php $i = 0; ?>
<?php foreach($data as $key => $row) : ?>
	<?php $sum = 0; ?>
	<table>
		<thead>
			<tr>
				<th colspan="4"><?php echo $key; ?>元以上</th>
			</tr>
		</thead>
		<tbody>
			<?php foreach($row as $item) : ?>
				<tr>
					<td width="70"><?php echo date('m月d日', $item['create_time']); ?></td>
					<td width="150"><?php echo $item['pay_name']; ?></td>
					<td width="60"><b><?php echo library_common::money_num($item['amount']); ?></b></td>
					<td></td>
				</tr>
				<?php $sum += $item['amount']; ?>
			<?php endforeach; ?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="4">
					共有 <b><?php echo count($row);?></b> 项
					&nbsp; / &nbsp;
					共计 <b><?php echo library_common::money_num($sum); ?></b> 元
					&nbsp; / &nbsp;
					占比 <b><?php echo round($sum / $sum_all * 100); ?>%</b>
				</td>
			</tr>
		</tfoot>
	</table>
<?php endforeach; ?>

<form>
<table>
	<tr>
		<th colspan="2">选项</th>
	</tr>
	<tr>
		<td width="100">选择时间</td>
		<td class="frm">
			<input type="hidden" name="m" value="finance" />
			<input type="hidden" name="a" value="pay_analytics" />
			<input type="text" name="start_time" value="<?php echo date('Y-m-d', $start_time); ?>" />
			~
			<input type="text" name="end_time" value="<?php echo date('Y-m-d', $end_time); ?>" />
			<input type="submit" value="提交" />
		</td>
	</tr>
</table>
</form>

<?php require VIEW_ROOT.'/common/footer.php'?>
